home *** CD-ROM | disk | FTP | other *** search
- /**************************************
- * *
- * *** HAPPy Pascal compiler *** *
- * initialize routine *
- * *
- * Copyright (c) H.Asano 1992,1994. *
- **************************************/
-
- #define EXTERN extern
-
- #include <signal.h>
- #include "pascomp.h"
-
- static void initscalars(void) ;
- static void initsets(void) ;
- static void entstdtypes(void) ;
- extern void entstdnames(void) ;
- extern void entundecl (void) ;
- extern Set *mkset(Set*,int,...) ;
- extern Set *orset(Set*,Set*) ;
- extern void initpcd(void) ;
- extern void initheap(void);
- extern void *Malloc(int) ;
- extern void real_err(int,int) ;
-
- /****************************************/
- /* init() :初期設定メイン */
- /****************************************/
- void init(void)
- {
- signal(SIGFPE,real_err) ; /* 浮動小数点例外処理の登録 */
- initheap() ; /* heapメモリの初期設定 */
- initscalars() ; /* スカラー項目の初期設定 */
- initsets() ; /* symbol set の 初期設定 */
- initpcd() ; /* P-codeの初期設定 */
-
- level = 0 ;
- top = 0 ;
- display[0].fname = nil ;
- display[0].flabel = nil ;
- display[0].occur = blck ;
-
- entstdtypes() ; /* 標準の型の登録 */
- entstdnames() ; /* 標準名の登録 */
- entundecl () ; /* 未定義の名前のための事前処理*/
-
- level = 1 ; /* 利用者定義の名前は水準1から*/
- top = 1 ;
- display[1].fname = nil ;
- display[1].flabel = nil ;
- display[1].occur = blck ;
- }
-
- /****************************************/
- /* initscalars() : スカラー項目初期設定 */
- /****************************************/
- static void initscalars(void)
- {
- defineinput = false ; /* input ファイル 未定義 */
- defineoutput = false ; /* outputファイル 未定義 */
- errorcount = 0 ; /* 発見したエラー数初期化 */
- lineno = 0 ; /* ソースの行番号初期化 */
- ic = 0 ; /* Pコードカウンタ 0に設定 */
- lc = outputadr+charmax ; /* 変数カウンタ初期設定 */
- ch = ' ' ; /* 読込文字初期化 */
- fwptr = nil ; /* 前方参照ポインタをクリア */
- }
-
- /****************************************/
- /* initsets() : 集合の初期設定 */
- /****************************************/
- static void initsets(void)
- {
- mkset(&constbegsys,
- addop,intconst,realconst,stringconst,ident,-1) ;
- mkset(&simptypebegsys, lparent,-1) ;
- orset(&simptypebegsys, &constbegsys) ;
- mkset(&typebegsys,
- arrow,packedsy,arraysy,recordsy,setsy,filesy,-1) ;
- orset(&typebegsys, &simptypebegsys) ;
- mkset(&typedels,
- arraysy,recordsy,setsy,filesy,-1) ;
- mkset(&blockbegsys,
- labelsy,constsy,typesy,varsy,procsy,funcsy,beginsy,-1);
- mkset(&selectsys,
- arrow,period,lbrack,-1) ;
- mkset(&facbegsys,
- intconst,realconst,stringconst,ident,lparent,lbrack,notsy,nilsy,-1);
- mkset(&statbegsys,
- beginsy,gotosy,ifsy,whilesy,repeatsy,forsy,withsy,casesy,-1) ;
- mkset(&statfolsys,
- semicolon,endsy,elsesy,untilsy,-1) ;
- }
-
- /****************************************/
- /* entstdtypes() : 標準の型登録 */
- /****************************************/
- static void entstdtypes(void)
- {
- /**** integer ****/
- intptr = (stp*)Malloc(sizeof(stp)) ;
- intptr->size = intsize ;
- intptr->form = scalar ;
- intptr->assignflag = true ;
- intptr->sf.sc.scalkind = standard ;
-
- /**** real ****/
- realptr = (stp*)Malloc(sizeof(stp)) ;
- realptr->size = realsize ;
- realptr->form = scalar ;
- realptr->assignflag = true ;
- realptr->sf.sc.scalkind = standard ;
-
- /**** char ****/
- charptr = (stp*)Malloc(sizeof(stp)) ;
- charptr->size = charsize ;
- charptr->form = scalar ;
- charptr->assignflag = true ;
- charptr->sf.sc.scalkind = standard ;
-
- /**** boolean ****/
- boolptr = (stp*)Malloc(sizeof(stp)) ;
- boolptr->size = boolsize ;
- boolptr->form = scalar ;
- boolptr->assignflag = true ;
- boolptr->sf.sc.scalkind = declared ; /* 列挙型はdeclaredである */
-
- /**** nil ****/
- nilptr = (stp*)Malloc(sizeof(stp)) ;
- nilptr->size = ptrsize ;
- nilptr->form = pointer ;
- nilptr->assignflag = true ;
- nilptr->sf.pt.eltype = nil ;
-
- /**** for alignment of parameters ****/
- parmptr = (stp*)Malloc(sizeof(stp)) ;
- parmptr->size = parmsize ;
- parmptr->form = scalar ;
- parmptr->assignflag = true ;
- parmptr->sf.sc.scalkind = standard ;
-
- /**** text ****/
- textptr = (stp*)Malloc(sizeof(stp)) ;
- textptr->size = charsize ;
- textptr->form = files ;
- textptr->assignflag = false ;
- textptr->sf.fi.texttype = true ;
- textptr->sf.fi.filtype = charptr ;
- }